package com.boby.homecamera.util;

import java.util.Calendar;

public class DateUtil {
    public static  long getTodayStartTimeMillis() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);  // 设置小时为 0
        calendar.set(Calendar.MINUTE, 0);       // 设置分钟为 0
        calendar.set(Calendar.SECOND, 0);       // 设置秒为 0
        calendar.set(Calendar.MILLISECOND, 0);  // 设置毫秒为 0
        return calendar.getTimeInMillis();      // 获取时间戳（毫秒）
    }
    /**
     * 获取指定时间戳所在天的 00:00:00 的时间戳（毫秒）
     */
    public static long getDayStartTimeMillis(long timeMillis) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(timeMillis);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTimeInMillis();
    }

    /**
     * 获取某天从 0 点开始经过的秒数（基于给定的时间戳）
     */
    public static int getDayStartTimeSecond(Long timeMillis) {
        if(timeMillis == null){
            return 0;
        }
        return (int) ((timeMillis - getDayStartTimeMillis(timeMillis)) / 1000);
    }
//    public static int getDayStartTimeMillis(Long timeMillis) {
//        if(timeMillis == null){
//            return 0;
//        }
//        return (int) ((timeMillis - getDayStartTimeMillis(timeMillis)));
//    }

}
